import { request } from '@/utils/http'
import axios from 'axios'
import { Key } from 'react'

//设置返回值和形参的类型
//在前面加一个type,可以一眼看出来这个位置引入的是类型
import type {
  getHosSetListParamsType,
  getHosSetListReturnType,
  addHospitalParamsType,
  updateHosSetParamsType
} from './model/hospitalSetTypes'
//在util中设置了发请求时的设置及拦截器,所以不用axios,用写好的request,写好的request返回来的数据只有data,所以在设置返回值的类型时只用设置data
//1.获取医院设置分页的请求
export const getHosSetListRequest = ({ page, limit, hosname, hoscode }: getHosSetListParamsType) => {
  // return axios.get(`/admin/hosp/hospitalSet/${page}/${limit}`,{
    //get后参数的类型,第一个传any,暂时用不到,第二个就是返回值的类型
    //第一个参数是用来限制返回的promise实例的类型,但是第一个参数是在第二个参数中去使用的,可以直接限制第二个参数,第一个参数直接写any
  return request.get<any,getHosSetListReturnType>(`/admin/hosp/hospitalSet/${page}/${limit}`, {
    params: {
      hosname,
      hoscode
    }
  })
}


//2.添加医院的请求
export const addHospitalRequest = (data:addHospitalParamsType)=>{
return request.post<any,null>('/admin/hosp/hospitalSet/save',data)
}


//3.根据id获取医院设置的请求
export const getHosSetItemFromIdRequest = (id:string)=>{
  return request.get<any,getHosSetListReturnType>(`/admin/hosp/hospitalSet/get/${id}`)
}

//4.根据id更新医院设置的请求
export const setHosSetItemFromIdRequest = (data:updateHosSetParamsType)=>{
  return request.put('/admin/hosp/hospitalSet/update',data)
}

//5.根据id删除医院
export const deleteHosSetFromIdRequest = (id:number)=>{
  return request.delete(`/admin/hosp/hospitalSet/remove/${id}`)
}


//6.点击批量删除删除医院
export const batchRemoveRequest = (ids:Key[])=>{
  return request.delete('/admin/hosp/hospitalSet/batchRemove',{
    data:ids
  })
}